package cn.edu.scau.cmi.xuchuangxiong.adapter;

import java.util.List;

public class SortUtil {
	
	public static void quickSort(List<Integer> intList, int low, int high)
	{
		if(low > high) return;
		int temp = intList.get(low);
		int i = low, j = high;
		while(i != j)
		{
			while(intList.get(j) >= temp && i < j) j--;
			while(intList.get(i) <= temp && i < j) i++;
			if(i < j)
			{
				swap(intList, i, j);
			}
		}
		intList.set(low, intList.get(i));
		intList.set(i, temp);
		quickSort(intList, low, i-1);
		quickSort(intList, i+1, high);
	}
	
	private static void swap(List<Integer> intList, int i, int j) {
		int t = intList.get(i);
		intList.set(i, intList.get(j));
		intList.set(j, t);
	}
	
	public List<Integer> sortInt(List<Integer> intList)
	{
		quickSort(intList, 0, intList.size()-1);
		return intList;
	}
	
	
}
